
/**
 * @Author: 陈瑞鹏
 * @Date:   2023-01-10 09:54:16
 * @Last Modified by:   陈瑞鹏
 * @Last Modified time: 2023-01-11 09:47:31
 */
import emailEntity from "../ctrs/email/emailEntity";
import netCtr from "../ctrs/netCtr";
import BaseGameComponent from "../libs/core/BaseGameComponent";
import { SceneManager } from "../libs/manager/SceneManager";

const { ccclass, property } = cc._decorator;
@ccclass
export default class emailCom extends BaseGameComponent {

  @property({ type: cc.Label, tooltip: "标题" })
  titleTxt: cc.Label = null;

  @property({ type: cc.Label, tooltip: "内容" })
  descTxt: cc.Label = null;

  @property({ type: cc.Sprite, tooltip: "icon" })
  icon: cc.Sprite = null;

  @property({ type: cc.Sprite, tooltip: "按钮icon" })
  btnIcon: cc.Sprite = null;

  private _emailEny: emailEntity = null;

  drawUi(data) {
    if (data) {
      this._emailEny = data;
    }
    // console.log(data);
    this.titleTxt.string = this._emailEny.title;
    this.descTxt.string = this._emailEny.isRecive ? "已领取" : this._emailEny.desc;
    let iconUrl = "ele/bx1";
    let btnIconUrl = "ele/lqBtn";
    if (this._emailEny.type == 1) {
      iconUrl = "ele/bx1";
      btnIconUrl = "ele/lqBtn";
      if (this._emailEny.isRecive) {
        this.btnIcon.node.parent.getComponent(cc.Button).interactable = false;
      }
    } else if (this._emailEny.type == 2) {
      iconUrl = "ele/emailIcon";
      btnIconUrl = "ele/ckBtn";
      let str = this._emailEny.desc.substring(0, 10);
      this.descTxt.string = str + "...";
      // if (this._emailEny.isRecive) {
      this.btnIcon.node.parent.getComponent(cc.Button).interactable = true;
      // }
    }

    cc.resources.load(iconUrl, cc.SpriteFrame, (err, sp: cc.SpriteFrame) => {
      this.icon.spriteFrame = sp;
    })

    cc.resources.load(btnIconUrl, cc.SpriteFrame, (err, sp: cc.SpriteFrame) => {
      this.btnIcon.spriteFrame = sp;

    })
  }

  /**
   * 点击领取
   */
  onLqClick(e, key) {

    if (this._emailEny.type == 1) {
      netCtr.ins.lqEamil(this._emailEny.uid);
    } else {
      SceneManager.getInstance().pushLayer("noticeLayer", this._emailEny);
    }
  }

  /**
   * 点击查看
   */
  onViewClick() {
    SceneManager.getInstance().pushLayer("noticeLayer", this._emailEny);
  }
}